package com.ruoyi.withdraw.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.withdraw.domain.withdraw;
import com.ruoyi.withdraw.service.IwithdrawService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 提现申请Controller
 * 
 * @author wuxiao
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/withdraw")
public class withdrawController extends BaseController
{
    @Autowired
    private IwithdrawService withdrawService;

    /**
     * 查询提现申请列表
     */
    @RequiresPermissions("withdraw:withdraw:list")
    @GetMapping("/list")
    public TableDataInfo list(withdraw withdraw)
    {
        startPage();
        List<withdraw> list = withdrawService.selectwithdrawList(withdraw);
        return getDataTable(list);
    }

    /**
     * 导出提现申请列表
     */
    @RequiresPermissions("withdraw:withdraw:export")
    @Log(title = "提现申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, withdraw withdraw)
    {
        List<withdraw> list = withdrawService.selectwithdrawList(withdraw);
        ExcelUtil<withdraw> util = new ExcelUtil<withdraw>(withdraw.class);
        util.exportExcel(response, list, "提现申请数据");
    }

//    /**
//     * 获取提现申请详细信息
//     */
//    @RequiresPermissions("withdraw:withdraw:query")
//    @GetMapping(value = "/{applyId}")
//    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
//    {
//        return AjaxResult.success(withdrawService.selectwithdrawByApplyId(applyId));
//    }

    /**
     * 新增提现申请
     */
    @RequiresPermissions("withdraw:withdraw:add")
    @Log(title = "提现申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody withdraw withdraw)
    {
        return toAjax(withdrawService.insertwithdraw(withdraw));
    }

    /**
     * 修改提现申请
     */
    @RequiresPermissions("withdraw:withdraw:edit")
    @Log(title = "提现申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody withdraw withdraw)
    {
        return toAjax(withdrawService.updatewithdraw(withdraw));
    }

    /**
     * 删除提现申请
     */
    @RequiresPermissions("withdraw:withdraw:remove")
    @Log(title = "提现申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(withdrawService.deletewithdrawByApplyIds(applyIds));
    }

    /**
     * 通过提现申请
     */
    @RequiresPermissions("withdraw:withdraw:means")
    @GetMapping(value = "/{applyId}")
    public AjaxResult means(@PathVariable("applyId") Long applyId) {
        int result = withdrawService.meanswithdrawByApplyId(applyId);

        if (result > 0) {
            return AjaxResult.success("提现申请已通过");
        } else {
            return AjaxResult.error("提现申请通过失败");
        }
    }

}
